package com.party.orders.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.party.domain.CurrentAccount;
import com.party.dto.Page;
import com.party.exception.ExceptionMsgEnum;
import com.party.exception.ServiceException;
import com.party.orders.mapper.CurrentAccountMapper;
import com.party.orders.service.CurrentAccountService;

/**
 * @author Caizhf
 * @date 2017年7月28日下午5:57:45
 * @version v.0.1
 * @email 1115054416@qq.com 
 *
 * <p>Description: </p>
 *
 */
@Service
public class CurrentAccountServiceImpl implements CurrentAccountService{
	@Autowired
	private CurrentAccountMapper mapper;
	
	@Override
	public CurrentAccount findById(Integer caid, String allOrderNum) {
		//二者不能同时没有
		if(caid==null&&allOrderNum==null)
			throw new ServiceException(ExceptionMsgEnum.CLIENT_PARAM_ERROR_MSG);
		CurrentAccount ca = mapper.findByallOrdersNumOrId(caid,allOrderNum);
		return ca;
	}

	@Override
	public Page list(Integer userId,Integer status ,int pageNum, int pageSize, Date startTime, Date endTime) {
		int totleRecord = mapper.countList(userId,status,startTime,endTime);
		Page page = null;
		if(pageNum==0)
			page = new Page(totleRecord,1);
		else
			//如果不为空，那么就按照想看的页码进行
			page = new Page(totleRecord, pageNum,pageSize);
		List<CurrentAccount> list = mapper.list(userId, status, pageNum, pageSize,startTime,endTime);
		page.setList(list);
		return page;
	}

	@Override
	public void delete(int caid) {
		if(mapper.delete(caid)==null)
			throw new ServiceException(ExceptionMsgEnum.SERVER_DB_NOTEXIT);
	}

}
